<template>
  <div style="height:100vh;
      background-image: url('/imgs/login/img.png');
      background-size: cover;
      background-position: center;
      overflow: hidden;
    ">
    <el-container style="padding: 30px;">
      <el-header>
        <el-row :gutter="10">
          <el-col :span="3">
            <img src="/imgs/login/logo.png" style="height: 50px;width: 100%">
          </el-col>
          <el-col :span="1">
            <img src="/imgs/login/verticalLine.png" style="height: 50px;width: 100%">
          </el-col>
          <el-col :span="20">
            <span style="color:#fff;font-size:30px;font-weight:bold;width: 100%">LBS智慧营销管理系统</span>
          </el-col>
        </el-row>
      </el-header>
      <el-main>
        <el-row type="flex" justify="center" align="middle" style="min-height: 100%;">
          <el-col :span="8">
            <el-card style="margin-top: 100px">
              <el-row >
                <el-col :span="10">
                  <img src="/imgs/login/img_1.png" style="margin-top: 10px;width: 200px;height:348px">
                </el-col>
                <el-col :span="14">
                  <h3 style="text-align: center;">欢迎登录LBS管理系统</h3>
                  <el-form label-position="top">
                    <!-- 视角选择 -->
                    <el-form-item>
                      <el-select v-model="user.view" placeholder="请选择视角" class="view-select">
                        <el-option label="平台视角" value="merchant"></el-option>
                        <el-option label="商家视角" value="user"></el-option>
                      </el-select>
                    </el-form-item>
                    <el-form-item label="用户名">
                      <el-input placeholder="请输入用户名" v-model="user.phone" ></el-input>
                    </el-form-item>
                    <el-form-item label="密码">
                      <el-input placeholder="请输入密码" show-password v-model="user.password"
                                :type="passwordVisible ? 'text' : 'password'"></el-input>
                    </el-form-item>
                    <!-- 验证码 -->
                    <el-form-item prop="captcha">
                      <el-input v-model="user.captcha" placeholder="请输入验证码" style="width: calc(100% - 120px);"></el-input>
                      <img  src="/imgs/login/img_2.png" style="width: 120px;height: 40px;">
                    </el-form-item>
                    <el-form-item>
                      <el-button type="primary" style="width: 100%;" @click="login">登录</el-button>
                    </el-form-item>
                  </el-form>
                </el-col>
              </el-row>
            </el-card>
          </el-col>
        </el-row>
      </el-main>
    </el-container>
  </div>
</template>

<script setup>
import {onMounted, ref} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";
import router from "../router";
import qs from "qs";

//1.定义对象用来保存用户输入的登录数据
const user = ref({view:'',phone: '', password: '',captcha:''});
const passwordVisible = ref(false);
//定义登录方法
const login = ()=>{
  if(user.value.captcha !== 'DG1S'){
    ElMessage.error('验证码错误!');
  }else{
  if(user.value.view === 'merchant') {
    axios.post( 'http://localhost:7070/passport/admin/login', user.value).then((response) => {
        console.log(response.data);
        ElMessage.success('登录成功!');
        localStorage.setItem('user', JSON.stringify(response.data.data));
        router.push('/platform');
    })
  }else if(user.value.view === 'user'){
    axios.post('http://localhost:7070/passport/user/login',user.value).then((response) => {
        ElMessage.success('登录成功!');
        localStorage.setItem('user', JSON.stringify(response.data.data));
        router.push('/');
    })
  }
  }
}

</script>

<style scoped>

</style>